Skip to content

Conversation

@expenses
Copy link
Contributor

No description provided.

@expenses
Copy link
Contributor Author

Currently getting this error:

thread 'main' (84556) panicked at internal/interpreter/dynamic_item_tree.rs:1103:25:
Native type not registered: StyledText

@ogoffart where should I be registering this?

@ogoffart
Copy link
Member

Native type not registered: StyledText

This is supposed to be registered in

rtti_for::<MarkdownText>(),

@expenses
Copy link
Contributor Author

Native type not registered: StyledText

This is supposed to be registered in

rtti_for::<MarkdownText>(),

Ohh, right, thanks. Part of the confusion here is that we have both component StyledText and property <styled-text> and they both correspond to rust structs of the same name

@ogoffart
Copy link
Member

Part of the confusion here is that we have both component StyledText and property and they both correspond to rust structs of the same name

Indeed. It is possible to have the item have a different struct name. For example Window vs WindowItem
So you can rename the struct in rust to StyledTextItem and in builtins.slint have export StyledTextItem as StyledText

@expenses expenses marked this pull request as ready for review November 18, 2025 17:40
@expenses
Copy link
Contributor Author

@tronical @ogoffart I've added tests to this now. Followup work is improving the escape function and C++ stuff. My preference would be to get this merged now and then do the rest later

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the tests, there is not yet test that test any of the generate code.

That should go in tests/cases/element/StyledText, even if its just testing that things compile, and doesn't panic.

(Ideally we shouyld also have rendering rest (eg screenshot tests), but since the screenshot test don't use a renderer that uses parley, this cannot be done now)

There should also be test that tests the error cases.

I also would like to see compile time check of the markdown validity.

}
}

pub fn escape_markdown(text: &str) -> alloc::string::String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have code with more backticks. That's actually how you escape them.

Which makes me think again that this function cannot really work in the case of code, as it means the "host" markdown will need more ticks.

Comment on lines 6 to 10
TestCase := Window {
property<styled-text> t1: @markdown("Hello {}", "World");
property<styled-text> t2: @markdown("Hello {}", "*World*");
property<styled-text> t3: @markdown("Hello *{}*", "World");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In new code, we can avoid using deprecated syntax.

Suggested change
TestCase := Window {
property<styled-text> t1: @markdown("Hello {}", "World");
property<styled-text> t2: @markdown("Hello {}", "*World*");
property<styled-text> t3: @markdown("Hello *{}*", "World");
}
export component TestCase inherits Window {
out property<styled-text> t1: @markdown("Hello {}", "World");
out property<styled-text> t2: @markdown("Hello {}", "*World*");
out property<styled-text> t3: @markdown("Hello *{}*", "World");
}

Also this file can be moved to tests/cases/types instead, since it doesn't test the StyledText element, but more the styled-text type.

};

/// Styled text that has been parsed and seperated into paragraphs
class StyledText
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default constructor leaves paragraphs uninitialized.
The refcount is not updated when the StyledText is copied.
The destructor don't delete memory.

We need to add functions cbindgen_private::slint_styled_text_{drop,clone,new}

api/cpp/lib.rs Outdated
}

#[unsafe(no_mangle)]
pub extern "C" fn slint_parse_markdown(text: &SharedString) -> i_slint_core::api::StyledText {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StyledText will have a destructor so we can't return it.
It should be slint_parse_markdown(text: &SharedString, out: &mut StyledText) or unsafe fn slint_parse_markdown(text: &SharedString, out: *mut StyledText) and we use core::ptr::write into it.

"Flickable",
"SimpleText",
"ComplexText",
"MarkdownText",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be renamed to StyledTextItem ?

@expenses expenses requested a review from ogoffart November 28, 2025 12:25
@expenses
Copy link
Contributor Author

@ogoffart @tronical we should finally be done here

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's merge that for now and do the rest in follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants